/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchngachluongException;
import doan.quanlycanbo.portlet.model.ngachluong;
import doan.quanlycanbo.portlet.service.base.ngachluongLocalServiceBaseImpl;

/**
 * 
 * @author Nguyen Tuan Vinh
 */
public class ngachluongLocalServiceImpl extends ngachluongLocalServiceBaseImpl {
	
	public ngachluong getByMaNgachLuong(long mangachluong) throws NoSuchngachluongException, SystemException{
		return ngachluongPersistence.findByMaNgachLuong(mangachluong);
	}
	
	public List<ngachluong> getAll() throws SystemException{
		return ngachluongPersistence.findAll();
	}
	
	public ngachluong addNgachLuong(ngachluong ngachluong1, long userId) throws SystemException{
		long mabang = CounterLocalServiceUtil.increment(ngachluong.class.getName());
		ngachluong ngachluong2 = ngachluongPersistence.create(mabang);
		ngachluong2.setGroupId(ngachluong1.getGroupId());
		ngachluong2.setCompanyId(ngachluong1.getCompanyId());
		ngachluong2.setLanguageId(ngachluong1.getLanguageId());
		ngachluong2.setMangachluong(ngachluong1.getMangachluong());
		ngachluong2.setTenngachluong(ngachluong1.getTenngachluong());

		try {
			resourceLocalService.addResources(ngachluong1.getCompanyId(), ngachluong1.getGroupId(), userId, 
					ngachluong.class.getName(), ngachluong2.getPrimaryKey(), false, true, true);
		} catch (PortalException e) {
			e.printStackTrace();
		}
		
		return ngachluongPersistence.update(ngachluong2, false);
	}
	
	public ngachluong updateCapUy(long mabang, String tenngachluong, long mangachluong) throws SystemException, NoSuchngachluongException{
		ngachluong ngachLuong = ngachluongPersistence.findByPrimaryKey(mabang);
		ngachLuong.setTenngachluong(tenngachluong);
		ngachLuong.setMangachluong(mangachluong);
		return ngachluongPersistence.update(ngachLuong, false);
	}
	
	public ngachluong deleteNgachLuong(long mabang) throws SystemException,NoSuchngachluongException,PortalException{
		ngachluong ngachLuong = ngachluongPersistence.findByPrimaryKey(mabang);
		return deleteNgachLuong(ngachLuong);
	}
	
	public ngachluong deleteNgachLuong(ngachluong ngachLuong) throws SystemException,PortalException{
		resourceLocalService.deleteResource(ngachLuong.getCompanyId(), ngachluong.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, ngachLuong.getPrimaryKey());
		return ngachluongPersistence.remove(ngachLuong);
	}
}